package com.example.erp;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import jakarta.servlet.http.HttpServletResponse;
import reactor.core.publisher.Flux;

/**
 * 采用自定义mcp服务，基于 openai 通过 llm 访问，实现一个天气管理服务。<br>
 * <p>
 * chatopenai前置条件：<br/>
 * 1、application.properties 配置 weather 指定服务地址;<br/>
 * 
 * chatopenai2前置条件：<br/>
 * 1、在 clientConfig.java 中注入 weather 配置信息<br/>
 * 
 * @author jiang 2025-03-20
 */

@RestController
public class ChatController {

	@Autowired
	private ChatClient chatClient;

//	http://localhost:8081/mcp/chat?input=上海今天天气如何？
	@GetMapping("/chat")
	public Flux<String> openaicall(@RequestParam String input, HttpServletResponse response) {
		response.setCharacterEncoding("UTF-8");
		// 流式返回
		return chatClient.prompt(input).stream().content();
	}
}